package xyz.labmem.main.modular.app.indexShow.controller

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import org.springframework.web.bind.annotation.*
import xyz.labmem.base.core.result.RV
import xyz.labmem.base.sys.base.BaseController
import xyz.labmem.base.sys.consts.PathPrefixConst
import xyz.labmem.main.modular.app.indexShow.controller.response.GlobalRes
import xyz.labmem.main.modular.app.indexShow.controller.response.ModuleRes
import xyz.labmem.main.modular.app.indexShow.service.AppShowAmountService
import xyz.labmem.main.modular.app.other.entity.AppOtherFunction
import xyz.labmem.main.modular.app.other.entity.SysUserMenus
import xyz.labmem.main.modular.app.other.mapper.AppOtherFunction_Mapper
import xyz.labmem.main.modular.app.other.mapper.sysUserMenus1Mapper
/**
 * @Author lty
 * @Date 2021/12/30 10:02
 */
@RestController
@Api(tags = ["首页展示接口"])
@RequestMapping("${PathPrefixConst.APP_PATH_PREFIX}indexShow")
class AppIndexShowController(
    private var appShowAmountService: AppShowAmountService,
    private var sysUserMenusMapper: sysUserMenus1Mapper,
    private var appotherfunctionMapper: AppOtherFunction_Mapper

    ) : BaseController() {

    private val packagePre = "xyz.labmem.main.modular.app."


    @GetMapping("zhgk")
    @ApiOperation(value = "综合概况")
    fun zhgk(): RV<List<ModuleRes>> {
        return success(appShowAmountService.getAmountByModel("${packagePre}zhgk",false))
    }

    @GetMapping("gmjj")
    @ApiOperation(value = "国民经济")
    fun nationalEconomy(): RV<List<ModuleRes>> {
        return success(appShowAmountService.getAmountByModel("${packagePre}gmjj",true))
    }



    @GetMapping("xxly")
    @ApiOperation(value = "新型领域")
    fun newFields(): RV<List<ModuleRes>> {
        return success(appShowAmountService.getAmountByModel("${packagePre}xxly",true))
    }

    @GetMapping("jtys")
    @ApiOperation(value = "交通运输")
    fun transportation(): RV<List<ModuleRes>> {
        return success(appShowAmountService.getAmountByModel("${packagePre}jtys",true))
    }

    @GetMapping("rmfk")
    @ApiOperation(value = "人民防空")
    fun civilAirDefense(): RV<List<ModuleRes>> {
        return success(appShowAmountService.getAmountByModel("${packagePre}rmfk",false))
    }

    @GetMapping("rmwz")
    @ApiOperation(value = "人民武装")
    fun peopleArmed(): RV<List<ModuleRes>> {
        return success(appShowAmountService.getAmountByModel("${packagePre}rmwz",false))
    }

    @GetMapping("zzdy")
    @ApiOperation(value = "政治动员")
    fun politicalMobilization(): RV<List<ModuleRes>> {
        return success(appShowAmountService.getAmountByModel("${packagePre}zzdy",false))
    }



    @GetMapping("wqzb")
    @ApiOperation(value = "武器装备")
    fun weaponry(): RV<List<ModuleRes>> {
        return success(appShowAmountService.getAmountByModel("${packagePre}wqzb",false))
    }

    @GetMapping("globa")
    @ApiOperation(value = "全局搜索")
    fun list(@ApiParam(value = "搜索值", required = true) value: String): RV<List<GlobalRes>> {
        val res = ArrayList<GlobalRes>()
        res.addAll(appShowAmountService.getAmount("${packagePre}zhgk","综合概况",value))
        res.addAll(appShowAmountService.getAmount("${packagePre}gmjj","国民经济",value))
        res.addAll(appShowAmountService.getAmount("${packagePre}xxly","新型领域",value))
        res.addAll(appShowAmountService.getAmount("${packagePre}jtys","交通运输",value))
        res.addAll(appShowAmountService.getAmount("${packagePre}wqzb","武器装备",value))
        res.addAll(appShowAmountService.getAmount("${packagePre}zzdy","政治动员",value))
        res.addAll(appShowAmountService.getAmount("${packagePre}rmfk","人民防空",value))
        res.addAll(appShowAmountService.getAmount("${packagePre}rmwz","人民武装",value))
        return success(res)
    }

    @GetMapping("cygn")
    @ApiOperation(value = "常用功能")
    fun cygn(): RV<List<AppOtherFunction>> {
        var user = getLoginUser()
        var menus = sysUserMenusMapper.selectListAll(user.id)
        var queryWrapper = QueryWrapper<AppOtherFunction>().apply {
            this.le("order_id",99)
            this.orderByAsc("order_id")
        }
        var list = appotherfunctionMapper.selectList(queryWrapper)
        for(app in list){
            app.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=app.prefix }) || user.superr==1
        }
        return success(list)
        /*
        var lists = ArrayList<ModuleRes>()
        val data1 = ModuleRes().apply {
            this.name = "基层武装部"
            this.prefix = "rmwzjcrmwzb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data1)
        val data2 = ModuleRes().apply {
            this.name = "军粮供应站"
            this.prefix = "jlgyzzxcjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data2)
        val data3 = ModuleRes().apply {
            this.name = "加油站"
            this.prefix = "fgwjyz"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data3)
        val data4 = ModuleRes().apply {
            this.name = "急救机构"
            this.prefix = "wjjjjjg"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data4)
        val data5 = ModuleRes().apply {
            this.name = "应急保障重点物资(储备物资)"
            this.prefix = "yjgljyjbzzdwzcbwzcjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data5)
        val data6 = ModuleRes().apply {
            this.name = "人防指挥所"
            this.prefix = "rfbrfzhscjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data6)
        val data7 = ModuleRes().apply {
            this.name = "人防疏散地域(基地)"
            this.prefix = "rfbrfssdyjdcjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data7)
        val data8 = ModuleRes().apply {
            this.name = "公路应急储备物资及装备"
            this.prefix = "glyjcbwzjzbcjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data8)
        val data9 = ModuleRes().apply {
            this.name = "军供站"
            this.prefix = "jgzcjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data9)
        val data10 = ModuleRes().apply {
            this.name = "国家交通战备物资储备库"
            this.prefix = "gjjtzbwzcbkcjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data10)
        val data11 = ModuleRes().apply {
            this.name = "医院"
            this.prefix = "wjjyyxx"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data11)
        val data12 = ModuleRes().apply {
            this.name = "公有云"
            this.prefix = "gyycjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data12)
        val data13 = ModuleRes().apply {
            this.name = "超算中心"
            this.prefix = "cszxcjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data13)
        val data14 = ModuleRes().apply {
            this.name = "发电企业"
            this.prefix = "fgwfdqy"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data14)
        val data15 = ModuleRes().apply {
            this.name = "民商站网资源"
            this.prefix = "mszwzycjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data15)
        val data16 = ModuleRes().apply {
            this.name = "气象台站"
            this.prefix = "qxjqxtzcjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data16)
        val data17 = ModuleRes().apply {
            this.name = "高速出入口"
            this.prefix = "gsglcrkcjb"
            this.num = 0
            this.hasPoint = true
            this.openType = false
            this.enShow = menus.contains(SysUserMenus().apply { userId=user.id;menuId=prefix }) || user.superr==1
        }
        lists.add(data17)
        return success(lists)*/
    }

}